package com.example.demo.service;

import com.example.demo.dao.GoodsDAO;
import com.example.demo.entity.Evaluate;
import com.example.demo.entity.Goods;
import com.example.demo.entity.Shop;
import com.example.demo.entity.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsService {
    @Autowired
    private GoodsDAO goodsDAO;

    public List<Goods> findAllGoods(Shop shop)
    {
        List<Goods> goods;
        goods = goodsDAO.findAllGoods(shop);
        return goods;
    }

    /*
   num 更改的数量
   goodsid 商品编号
    */
    public void updateGoodsNum(Goods goods)
    {
        goodsDAO.updateGoodsNum(goods);
    }

    public Goods findGoodsById(int goodsid)
    {
        return goodsDAO.findGoodsById(goodsid);
    }

    public List<Goods> findGoodsByType(Goods goods)
    {
        return goodsDAO.findGoodsByType(goods);
    }

    public List<Evaluate> findGoodsEvaluate(Evaluate evaluate){return goodsDAO.findGoodsEvaluate(evaluate);};

    public void insertGoodsEvaluate(Evaluate evaluate){goodsDAO.insertGoodsEvaluate(evaluate);};

    public Type getTypeByName(Type type){return goodsDAO.getTypeByName(type);};

    public Type getTypeById(int id){return goodsDAO.getTypeById(id);};

    public List<Type> getAllTypes(){return goodsDAO.getAllTypes();};

    public void insertType(Type type){goodsDAO.insertType(type);};

    public void updateVolume(Type type){goodsDAO.updateVolume(type);};

    public List<Goods> findAllGoodsBySidAndMsg(int sid,String searchMsg,int currentPage){
        int start = (currentPage-1)*10;
        return goodsDAO.findGoodsBySidAndMsg(sid,searchMsg,start);
    }
    public Evaluate searchEvaluate(Evaluate evaluate)
    {
        return goodsDAO.searchEvaluate(evaluate);
    }
    public int findAllGoodsBySidAndMsgTotal(int sid,String searchMsg){
        return goodsDAO.findAllGoodsBySidAndMsgTotal(sid,searchMsg);
    }

    public void deleteGoodsById(int id){
        goodsDAO.deleteGoodsById(id);
    }

    public void editGoods(Goods goods){
        goodsDAO.editGoods(goods);
    }
    public void addGoods(Goods goods){
        goodsDAO.addGoods(goods);
    }

}
